import 'package:flutter/material.dart';
import 'package:flutter_custom_bottom_tab_bar/tabbar.dart';
import 'package:flutter_custom_bottom_tab_bar/eachtab.dart';
import 'dart:ui';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yres/pages/event/OrderTypeEvent.dart';
import 'package:flutter_yres/tool/application.dart';
import 'package:flutter_yres/tool/constant.dart';

import 'AllOrderPage.dart';

class OrderPage extends StatefulWidget {
  int index = 0;
  OrderPage({Key key, @required this.index}) : super(key: key);
  @override
  State<StatefulWidget> createState() {
    return new OrderView();
  }
}

class OrderView extends State<OrderPage> with SingleTickerProviderStateMixin {
  TabController _tabController;
  String badgeNo1;
  var titles = ['全部', '已付款', '已结算', "已失效"];
  String value = "淘宝订单";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(
        vsync: this, initialIndex: widget.index, length: titles.length);
    badgeNo1 = '12';
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    final width = size.width;
    return Scaffold(
      appBar: AppBar(
          title: Center(
            child: DropdownButton<String>(
              value: value,
              // icon: Icon(Icons.arrow_downward),
              iconSize: 24,
              style: TextStyle(color: Colors.black,fontSize: ScreenUtil.getInstance().setSp(35)),
              underline: Container(
                height: 0,
                color: Colors.deepPurpleAccent,
              ),
              onChanged: (String newValue) {
                setState(() {
                  value = newValue;
                });
                APPLIC.eventBus.fire(OrderEventTypeEvent(value=="淘宝订单"?"tb":"pdd"));
              },
              items: <String>['淘宝订单', '拼多多订单']
                  .map<DropdownMenuItem<String>>((String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              }).toList(),
            ),
          ),
          elevation: 0.5,
          backgroundColor: white,
          iconTheme: new IconThemeData(color: black_99),
          brightness: Brightness.light,
          bottom: TabContainer(
              // alignment: Alignment.center,
              color: Colors.white,
              child: Stack(
                overflow: Overflow.clip,
                children: <Widget>[
                  Container(
                    child: new TabBar(
                      isScrollable: true,
                      controller: _tabController,
                      indicatorColor: mainColor,
                      labelColor: mainColor,
                      labelPadding: EdgeInsets.all(0),
                      unselectedLabelColor: Colors.black,
                      tabs: <Widget>[
                        EachTab(
                          text: titles[0],
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                        EachTab(
                          text: titles[1],
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                        EachTab(
                          text: titles[2],
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                        EachTab(
                          text: titles[3],
                          textStyle: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                      ],
                    ),
                  ),
                ],
              ))),
      body: TabBarView(controller: _tabController, children: <Widget>[
        Center(
            child: new AllOrderPage(
          type: 0,
        )),
        Center(
            child: AllOrderPage(
          type: 1,
        )),
        Center(
            child: AllOrderPage(
          type: 2,
        )),
        Center(
            child: AllOrderPage(
          type: 3,
        )),
      ]),
    );
  }
}
